package splb

import (
	"server/amtf"
	"server/global"
	"server/model/common/response"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

func A成组件() (组件 *amtf.S组件) {
	组件 = &amtf.S组件{
		Name:   "商品类别",
		A英文名:   "splb",
		Amodel: Smodel{},
		A其他api: &S其他api{},
	}
	return
}

type Smodel struct {
	amtf.S基础model
	A类别   *string `json:"类别" gorm:"column:类别;comment:;"`
	A父级id *int    `json:"父级id" gorm:"column:父级id;comment:;"`
}

func (Smodel) TableName() string {
	return "lysd_商品类别"
}

type S其他api struct {
}

func (a *S其他api) A取选项集(c *gin.Context) {
	dataSource, err := A取选项集()
	if err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:"+err.Error(), c)
		return
	}
	response.OkWithData(dataSource, c)
}

func A取选项集() (res map[string][]map[string]any, err error) {
	res = make(map[string][]map[string]any)

	父级id := make([]map[string]any, 0)

	global.GVA_DB.Table("lysd_商品类别").Where("deleted_at IS NULL").Select("类别 as label,id as value").Scan(&父级id)
	res["父级id"] = 父级id
	return
}
